package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.base.exception.XueChengPlusException;
import com.xuecheng.content.mapper.CourseTeacherMapper;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 课程-教师关系表 服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class CourseTeacherServiceImpl extends ServiceImpl<CourseTeacherMapper, CourseTeacher> implements CourseTeacherService {
    @Autowired
    private CourseTeacherMapper courseTeacherMapper;

    @Override
    public List<CourseTeacher> listCourseTeacher(Long id) {
        QueryWrapper<CourseTeacher> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id", id);
        return courseTeacherMapper.selectList(wrapper);
    }

    /**
     * 新增教师
     *
     * @param courseTeacher
     * @return
     */
    @Override
    public CourseTeacher createCourseTeacher(CourseTeacher courseTeacher) {
        //新增
        if (courseTeacher.getId() == null) {
            courseTeacher.setCreateDate(LocalDateTime.now());
            courseTeacherMapper.insert(courseTeacher);
            return courseTeacherMapper.selectById(courseTeacher);
        //修改
        } else {
            courseTeacherMapper.updateById(courseTeacher);
            return courseTeacherMapper.selectById(courseTeacher);
        }

    }

    @Override
    public void deleteTeachplan(Long courseId,Long id) {
        courseTeacherMapper.deleteById(id);
    }
}
